<{css src="style.css" app="desktop"}>
<form id="rolesform" action="index.php?ctl=roles&act=save" method="post">
  <div style="text-align:right;padding:3px 18px"><{help docid="101" type="link"}><{t}>点击查看帮助<{/t}><{/help}></div>
  <div class="division">
    <b><{t}>角色名称<{/t}>: </b>
    <input type="text" vtype="required" name="role_name" value="<{$roles.role_name}>" class="x-input " autocomplete="off">
  </div>

  <div class='division'>
    <h4><{t}>角色权限<{/t}></h4>
    <input type='hidden'  vtype='requiredcheckbox'/>
    <{foreach from=$workgrounds item=workground name=d }>
    <div class="row clearfix clear rules">
      <div class="left"><strong><{$workground.menu_title}></strong></div>
      <div class="right">
        <ul class="clearfix">
          <{foreach from=$workground.permissions item=permission key=key}>
          <li>
          <label>
            <input type="checkbox" name="workground[]" value="<{$permission.permission}>" <{if $permission.checked}>checked=checked<{/if}>/>
            <{$permission.menu_title}>
          </label>
          </li>
          <{/foreach}>
        </ul>
      </div>
    </div>
    <{/foreach}>

    <div class="row clearfix clear rules">
      <div class="left"><strong><{t}>控制面板<{/t}></strong></div>
      <div class="right">
        <ul class="clearfix">
          <{foreach from=$adminpanels item=adminpanel key=key}>
          <li>
            <label>
              <input  type="checkbox" name="workground[]" value="<{$adminpanel.permission}>" <{if $adminpanel.checked}>checked=checked<{/if}>/>
              <{$adminpanel.menu_title}>
            </label>
          </li>
          <{/foreach}>
        </ul>
      </div>
    </div>

    <div class="row clearfix clear rules">
      <div class="left"><strong><{t}>桌面挂件<{/t}></strong></div>
      <div class="right">
        <ul class="clearfix">
          <{foreach from=$widgets item=widget key=key}>
          <li>
            <label>
              <input  type="checkbox" name="workground[]" value="<{$widget.addon}>" <{if $widget.checked}>checked=checked<{/if}>/>
              <{$widget.menu_title}>
            </label>
          </li>
          <{/foreach}>
        </ul>
      </div>
    </div>

    <{if $others}>
    <div class="row clearfix clear" style="padding:5px;">
      <div class="span-2"><strong><{t}>其他<{/t}></strong></div>
      <div class="span-13" style="width:528px;">
        <div class="clearfix">
          <{foreach from=$others item=other key=key}>
          <div class="span-auto">
            <label>
              <input  type="checkbox" name="workground[]" value="<{$other.permission}>" <{if $other.checked}>checked=checked<{/if}>/>
              <{$other.menu_title}>
            </label>
          </div>
          <{/foreach}>
        </div>
      </div>
    </div>
    <{/if}>

  </div>
</form>


<{area inject=".mainFoot"}>
<div class="table-action">
  <{button label=$___desktop="确定"|t:'desktop' id="rolesform-submit" class="btn-primary"}>
</div>
<{/area}>
<script>
  function nameCheck(input){
    id = input.value;
    role_id = $('roleID').value;
    if((input.checked)){
      new Request.HTML({url:'index.php?app=desktop&ctl=roles&act=get_permission',method:'post',
        update:$(input).getNext(),data:'role_id='+role_id+'&name='+encodeURIComponent(input.value=input.value.trim())}).send();
      $('workground'+id).setStyle('display','block');
    }
    else{
      $('workground'+id).setStyle('display','none').empty();;
    }

  }

</script>
<script>
  (function(){
    var _form = $('rolesform');
    var btn =$('rolesform-submit');
    var finder = finderGroup['<{$env.get.finder_id}>'];

    _form.store('target',{
      onComplete:function(){
      },
      onSuccess:function(response){
        var hash_res_obj = JSON.decode(response);
        if (hash_res_obj.success != undefined && hash_res_obj.success != ""){
          try{
            var _dialogIns = btn.getParent('.dialog').retrieve('instance');
          }catch(e){}

          if(_dialogIns){
            _dialogIns.close();
            finder.refresh.delay(400,finder);

          }
        }
      }

    });

    btn.addEvent('click',function(){
      _form.fireEvent('submit',{stop:$empty});
    });

  })();

</script>
